package cording.example.addressList.mybatis.mapper;

import cording.example.addressList.mybatis.entity.Contact;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Optional;

public interface ContactListMapper {
    @Select("select * from contacts")
    List<Contact> findAll();
    @Delete("delete from contacts where id = #{id}")
    void deleteById(Long id);
    // 修改为返回 Optional<Contact>
    @Select("select * from contacts where id = #{id}")
    Optional<Contact> findById(Long id);
    void save(Contact contact);
    @Insert("insert into contacts (name, phone_number, email, school, gender, birth_year, major) " +
            "values"+"(#{name},#{phoneNumber},#{email},#{school},#{gender},#{birthYear},#{major})")
    void add(Contact contact);
    @Select("select * from contacts where phone_number = #{phoneNumber}")
    Contact findByPhoneNumber(String phoneNumber);
    @Select("select * from contacts where email = #{email}")
    Contact findByEmail(String email);
    @Select("select * from contacts where phone_number = #{phoneNumber}")
    List<Contact> findByPhoneNumberContaining(String phoneNumber);
    @Select("select * from contacts where name = #{name}")
    List<Contact> findByNameContaining(String name);
}
